import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/dao/ImDepartmentDao.dart';
import 'package:im_app/im/pojo/ImPojo.dart';
import 'package:im_app/im/util/DbUtil.dart';
import 'package:im_app/im/util/ImSingleton.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

void main() {

  test("insert department", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");
    ImSingleton.getInstance()?.dataBase = database;

    var departmentDao = ImDepartmentDao();
    var department = ImDepartment(currentUserId: 'u001', code: 'u001', name: 'u001', description: 'u001');
    await departmentDao.inserts([department]);
    database.close();
  });

  test("get department", () async {
    sqfliteFfiInit();
    databaseFactory = databaseFactoryFfi;
    Database database = await DbUtil.connect("imtest.db");
    ImSingleton.getInstance()?.dataBase = database;

    var departmentDao = new ImDepartmentDao();
    List<ImDepartment> result = await departmentDao.getAll();
    print("data: ${result[0].name} ");
    database.close();
  });
}